<?php

namespace app\api\controller\User;

use app\services\UserHistoryService;
use plugin\admin\app\model\UserHistory;
use support\Request;

class HistoryController
{
    public function list(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);

            $data = UserHistoryService::list($page, $length, UserHistory::VIDEO);

            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function drop(Request $request)
    {
        try {
            $id = $request->post('id');

            if (empty($id)) {
                throw new \Exception('ID不能为空');
            }

            UserHistoryService::drop(UserHistory::VIDEO, $id);

            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }
}